package com.yuwei.device.adapter

import android.annotation.SuppressLint
import android.graphics.Color
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.yuwei.device.R
import com.yuwei.http.entity.DeviceEntityItem

class DeviceAdapter : BaseQuickAdapter<DeviceEntityItem, BaseViewHolder>(
    R.layout.device_item
) {
    val orange = Color.parseColor("#F97316")
    val green = Color.parseColor("#22C55E")
    override fun convert(holder: BaseViewHolder, item: DeviceEntityItem) {
        holder.setText(R.id.device_name, "项目名称/设备名称："+item.deviceName)
        val textView = holder.getView<TextView>(R.id.device_status)
        when(item.status){
            "正常"->{
                textView.setTextColor(green)
                holder.setText(R.id.device_status,item.status)
                textView.setBackgroundResource(R.drawable.failure_rate_bg2)
            }
            "故障"->{
                textView.setTextColor(orange)
                holder.setText(R.id.device_status,item.status)
                textView.setBackgroundResource(R.drawable.failure_rate_bg)
            }
        }
        holder.setText(R.id.device_address,item.installationLocation)
        holder.setText(R.id.device_failure_rate,"${(item.failureRate*100)}%")
    }
}